home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / iDebugger / iDebugger.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.2 KB  |  214 lines

  1. // The 'yum ' Gestalt values.  They seem to be the same on Graphite
  2. // iBooks and iMacs.  Convenient.  Flavored iMacs available at MacHack
  3. // don't seem to have this Gestalt selector.  My (Geoff Adams') Lombard
  4. // doesn't.  iBooks do.
  5.  
  6. #define kTangerineYum 0x0000083c
  7. #define kBlueberryYum 0x00000835
  8. #define kGraphiteYum  0x0000083e
  9.  
  10. // The RGB values we've selected almost at random:
  11.  
  12. #define kTangerineColor_Red   0xFFFF
  13. #define kTangerineColor_Green 0x91EA
  14. #define kTangerineColor_Blue  0x3333
  15.  
  16. #define kBlueberryColor_Red   0x5b5b
  17. #define kBlueberryColor_Green 0x8787
  18. #define kBlueberryColor_Blue  0xf2f2
  19.  
  20. #define kGraphiteColor_Red    0xc228
  21. #define kGraphiteColor_Green  0xc228
  22. #define kGraphiteColor_Blue   0xc228
  23.  
  24.  
  25.  
  26. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  27.     #error Sorry Can't do that
  28. #endif
  29.  
  30. //#include <MixedMode.h>
  31. //#include <Appearance.h>
  32. //#include <SpeechSynthesis.h>
  33. #include <A4Stuff.h>
  34.  
  35. #include <Files.h>
  36. #include <Folders.h>
  37. #include <Gestalt.h>
  38. #include <Resources.h>
  39. #include <Quickdraw.h>
  40.  
  41.  
  42. // Tell MetroWerks the procInfo for main
  43. ProcInfoType __procinfo =  kPascalStackBased;
  44. pascal void main(void)
  45. {
  46.     THz            theZone;
  47.     
  48.     long        yumValue;
  49.     RGBColor    machineColor;
  50.     
  51.     OSErr        theErr;
  52.     UInt16        index;
  53.     short        vRefNum;
  54.     long        dirID;
  55.  
  56.     CInfoPBRec    cPB;
  57.     OSErr        result;
  58.     FSSpec        xDBGR_Startup;
  59.     Boolean        found = false;
  60.  
  61.     FSSpec        debuggerSpec;
  62.     Handle        mctbRes;
  63.  
  64.     // get globals
  65.     EnterCodeResource();
  66.  
  67.     // make sure we are in the system heap
  68.     // (We probably don't need to do this.)
  69.     theZone = GetZone();
  70.     SetZone(SystemZone());
  71.  
  72. //    DebugStr("\pWe're off!");
  73.     
  74.     // First, Get the 'yum ' Gestalt value.  This contains a description of the
  75.     // color, presumably among other things.
  76.     theErr = Gestalt('yum ', &yumValue);
  77.     if     (theErr == noErr) {
  78.  
  79.         // Well, we have a Yum! value.  Keep going...
  80.         // Figure out what color it should be.
  81.         switch (yumValue) {
  82.         
  83.             case kTangerineYum:
  84.                 machineColor.red =   kTangerineColor_Red;
  85.                 machineColor.green = kTangerineColor_Green;
  86.                 machineColor.blue =  kTangerineColor_Blue;
  87.                 break;
  88.  
  89.             case kBlueberryYum:
  90.                 machineColor.red =   kBlueberryColor_Red;
  91.                 machineColor.green = kBlueberryColor_Green;
  92.                 machineColor.blue =  kBlueberryColor_Blue;
  93.                 break;
  94.  
  95.             case kGraphiteYum:
  96.                 machineColor.red =   kGraphiteColor_Red;
  97.                 machineColor.green = kGraphiteColor_Green;
  98.                 machineColor.blue =  kGraphiteColor_Blue;
  99.                 break;
  100.  
  101.             default:
  102.                     DebugStr("\pUnknown yum value.");
  103.  
  104.         }
  105.         
  106.         
  107.         // Find the xDBGR_Startup INIT file (creator 'DBGR').
  108.         // Get its 'TDid' resrource, which contains the dirID of the directory
  109.         // containing "The Debugger"
  110.         theErr = FindFolder(-1, kExtensionFolderType, false /* createFolder */,
  111.                             &vRefNum, &dirID);
  112.         
  113.         index = 1;
  114.         do {
  115.             cPB.dirInfo.ioFDirIndex = index;
  116.             cPB.dirInfo.ioVRefNum = vRefNum;
  117.             cPB.dirInfo.ioDrDirID = dirID;
  118.             result = PBGetCatInfoSync(&cPB);        
  119.  
  120.             if ( result == noErr ) {
  121.                 if ( (cPB.hFileInfo.ioFlAttrib & ioDirMask) == 0 &&
  122.                         cPB.hFileInfo.ioFlFndrInfo.fdType == 'INIT' && 
  123.                         cPB.hFileInfo.ioFlFndrInfo.fdCreator == 'DBGR') {
  124.  
  125.                     FSMakeFSSpec(vRefNum, dirID, cPB.hFileInfo.ioNamePtr, &xDBGR_Startup);
  126.                     found = true;
  127.                     
  128.                 }
  129.             } else {
  130. //                DebugStr("\pPBGetCatInfoSync returned an error.");
  131.             }    
  132.  
  133.             ++index; /* prepare to get next item */
  134.         } while ( result == noErr && ! found); /* time to fall back a level? */
  135.  
  136. //        if (! found)
  137. //                DebugStr("\pFailed to find xDBGR_Startup");
  138.  
  139.         // If we fail to find xDBGR_Startup, who the hell cares?!
  140.         if (found) {
  141.  
  142.             // Open the startup INIT, and grab its TDid 0 resource.
  143.             short refNum = FSpOpenResFile(&xDBGR_Startup, fsRdPerm);
  144.  
  145.             Handle ourTDid = Get1Resource('TDid', 0);
  146.             
  147. //            if (ourTDid == NULL)
  148. //                DebugStr("\pFailed to find TDid resource.");
  149.  
  150.             if (ourTDid != NULL) {
  151.             
  152.                 dirID = ** ((long **) ourTDid);
  153.                 
  154.                 CloseResFile(refNum);
  155.                 
  156.                 // Now, find The Debugger by file name in that directory (dirID)
  157.                 
  158.                 /* theErr = */ FSMakeFSSpec(-1, dirID, "\pThe Debugger", &debuggerSpec);
  159.                 
  160.  
  161.                 // Next, open it, and find the 'mctb' 0 [menu color table] resource.
  162.                 // The six bytes at offset 0x18 are an RGB color.
  163.                 
  164.                 refNum = FSpOpenResFile(&debuggerSpec, fsRdWrPerm);
  165.                 
  166.                 mctbRes = Get1Resource('mctb', 0);
  167.  
  168.                 if (mctbRes == NULL) {
  169. //                    DebugStr("\pFailed to find mctb resource");
  170.                     CloseResFile(refNum);
  171.                 }
  172.                 
  173.                 if (mctbRes != NULL) {
  174.                 
  175.                     Ptr colorPointer = (*mctbRes + 0x18);
  176.                     RGBColor currentColor = *(RGBColor *) colorPointer;
  177.  
  178.                     // Don't bother changing anything if it's already set up
  179.                     // for the right color.  This ought to be the normal case, anyway.
  180.                     if (currentColor.red != machineColor.red || 
  181.                         currentColor.green != machineColor.green ||
  182.                         currentColor.blue != machineColor.blue) {
  183.  
  184. //                        DebugStr("\pSetting color value...");
  185.                         
  186.                         // Modify the resource in memory
  187.                         *(RGBColor *)colorPointer = machineColor;
  188.  
  189.                         // Make sure it gets written to disk
  190.                         ChangedResource(mctbRes);
  191.                         WriteResource(mctbRes);
  192.                         UpdateResFile(refNum);
  193.                     }
  194.                     
  195.                     CloseResFile(refNum);
  196.                     
  197.                 }
  198.  
  199.             }
  200.             
  201.         }
  202.  
  203.     }
  204.     
  205.     
  206.  
  207.     // restore to original heap
  208.     // (We probably don't need to do this, either.)
  209.     SetZone(theZone);
  210.     // restore globals
  211.     ExitCodeResource();
  212. }
  213.  
  214.